﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WenDangOne.ViewModel.common;

namespace LianChuDemo.SqlServerDal
{
    public class BaseDal
    {
        protected SystemCenterDbContext _systemCenterDbContext;

        //注入ef的的上下文
        public BaseDal(SystemCenterDbContext systemCenterDbContext)
        {
            _systemCenterDbContext = systemCenterDbContext;

        }

        /// <summary>
        /// Dal基类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public PagerResult<T> BasePageSearch<T>(IQueryable<T> query, SearchModel searchModel) where T : class, new()
        {
            //提取总行数
            int total = query.Count();
            PagerResult<T> result = new PagerResult<T>()
            {
                PageCount = (int)Math.Ceiling((decimal)total / searchModel.PageSize),
                Total = total,

                Data = query.Skip(searchModel.Start).Take(searchModel.PageSize).ToList(),
                PageIndex = searchModel.PageIndex
            };
            return result;
        }
    }
}
